﻿Friend Class Layer
	Public Property Textures As Texture2D()
	Public Property ScrollRate!

	Public Sub New(content As ContentManager, basePath As String, scrollRate!)
		'asumsikan tiap layer hanya punya 3 segment
		Textures = New Texture2D(3) {}
		For i% = 0 To 2
			Textures(i) = content.Load(Of Texture2D)(basePath & "_" & i)
		Next
		scrollRate = scrollRate
	End Sub
	Public Sub Draw(SpriteBatch As SpriteBatch, cameraPosition!)
		'asmusikan tiap segment punya lebar yang sama
		Dim segmentWidth% = Textures(0).Width

		'hitung segment mana yang akan di draw dan berapa banyak offsetnya
		Dim x! = cameraPosition * ScrollRate
		Dim leftSegment% = CInt(Math.Floor(x / segmentWidth))
		Dim rightSegment% = leftSegment + 1
		x = (x / segmentWidth - leftSegment) * -segmentWidth

		SpriteBatch.Draw(Textures(leftSegment Mod Textures.Length), New Vector2(x, 0.0F), Color.White)
		SpriteBatch.Draw(Textures(rightSegment Mod Textures.Length), New Vector2(x + segmentWidth, 0.0F), Color.White)
	End Sub


End Class